import { getApi, changeItemApi } from './api';
export default {
    namespace: 'agent',
    state: {
        list: [],
        item: {}
    },
    reducers: {
        save(state, { payload }) {
            const newState = Object.assign({}, state, payload);
            return newState;
        },
    },
    effects: {
        *getList({ payload }, { put, call }) {
            const response = yield call(getApi, payload);
            yield put({
                type: 'save',
                payload: { list: response},
            });
        },
        *getOnly({ payload }, { put, call }) {
            const response = yield call(getApi, payload);
            yield put({
                type: 'save',
                payload: { item: response[0]},
            });
        },
        *saveOnly({ payload }, { call }) {
            yield call(changeItemApi, payload);
        }
    }
};
